﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;
using Infragistics.Win.UltraWinGrid;
using Infragistics.Win.UltraWinEditors;
using System.Windows.Forms;

namespace POS_NEW
{
    internal class myProgress
    {
        // Fields
        public static int ConfigSale;
        private static DataSet ds = new DataSet();
        public static int ID_Empolyee;
        public static string InformationKho;
        public static int Kho;
        public static string Name;
        public static string NameKho;
        public static int Permiss;
        public static string ID_ChiNhanh = "1";
        public static string TinhTrang = "1";
        public static string PrintCount = "1";
        public static string ID_TheTraTruoc = "100001";
        public static string ID_NhanVien = "10001";
        public static DateTime NgayLamViec = DateTime.Now;
        public static string SoLo = "1";
        // Methods
        public static void comboNoneParam(string store, UltraCombo cb,string DisplayMember, string ValueMember)
        {
            object[] par = new object[0];
            ds = AccessDataLayer.Execute(store, CommandType.StoredProcedure, par);
            DataTable table = new DataTable();
            table = ds.Tables[0];
            cb.DataSource = table;
            cb.DisplayMember = table.Columns[DisplayMember].ToString();
            cb.ValueMember = table.Columns[ValueMember].ToString();
        }

        public static void comboWithParam(object[] par, string store, UltraCombo cb, string DisplayMember, string ValueMember)
        {
            ds = AccessDataLayer.Execute(store, CommandType.StoredProcedure, par);
            DataTable table = new DataTable();
            table = ds.Tables[0];
            cb.DataSource = table;
            cb.DisplayMember = table.Columns[DisplayMember].ToString();
            cb.ValueMember = table.Columns[ValueMember].ToString();
        }
        public static void comboEditorNoneParam(string store, UltraComboEditor cb, string DisplayMember, string ValueMember)
        {
            object[] par = new object[0];
            ds = AccessDataLayer.Execute(store, CommandType.StoredProcedure, par);
            DataTable table = new DataTable();
            table = ds.Tables[0];
            cb.DataSource = table;
            cb.DisplayMember = table.Columns[DisplayMember].ToString();
            cb.ValueMember = table.Columns[ValueMember].ToString();
        }
        public static void comboEditorWithParam(object[] par, string store, UltraComboEditor cb, string DisplayMember, string ValueMember)
        {
            ds = AccessDataLayer.Execute(store, CommandType.StoredProcedure, par);
            DataTable table = new DataTable();
            table = ds.Tables[0];
            cb.DataSource = table;
            cb.DisplayMember = table.Columns[DisplayMember].ToString();
            cb.ValueMember = table.Columns[ValueMember].ToString();
        }
        

        public static bool CompareDate(string strdatecompare)
        {
            string str = strdatecompare.Substring(0, 2);
            string str2 = strdatecompare.Substring(2, 2);
            string str3 = strdatecompare.Substring(4);
            string s = str2 + "/" + str + "/" + str3;
            DateTime time = new DateTime();
            DateTime date = DateTime.Now.Date;
            try
            {
                time = DateTime.Parse(s);
            }
            catch (Exception)
            {
            }
            return (time.CompareTo(date) == 0);
        }


        public static string ganMaPhieu(string storeName, string kitu, string chuoibandau, int index)
        {
            string str = "";
            object[] par = new object[0];
            DataSet set = new DataSet();
            set = AccessDataLayer.Execute(storeName, CommandType.StoredProcedure, par);
            if (set.Tables[0].Rows.Count > 0)
            {
                int num = Convert.ToInt32(set.Tables[0].Rows[0].ItemArray[0].ToString().Substring(index)) + 1;
                if (num < 10)
                {
                    return (kitu + "000" + num);
                }
                if (num >= 10)
                {
                    return (kitu + "00" + num);
                }
                if (num >= 100)
                {
                    return (kitu + "0" + num);
                }
                if (num >= 0x3e8)
                {
                    str = kitu + num;
                }
                return str;
            }
            return chuoibandau;
        }

        public static void gridviewNoneParam(string store, UltraGrid grid)
        {
            object[] par = new object[0];
            DataSet set = new DataSet();
            set = AccessDataLayer.Execute(store, CommandType.StoredProcedure, par);
            grid.DataSource = set.Tables[0];
        }

        public static void gridviewWithParam(object []par, string store, UltraGrid grid)
        {
            DataSet set = new DataSet();
            set = AccessDataLayer.Execute(store, CommandType.StoredProcedure, par);
            grid.DataSource = set.Tables[0];
        }

        public static string invertNgayThangNam(string ngay, int flag)
        {
            string[] strArray;
            string str = "";
            string str2 = "";
            string str3 = "";
            switch (flag)
            {
                case 0:
                    strArray = ngay.Split(new char[] { '/' });
                    str = strArray[0].ToString();
                    str2 = strArray[1].ToString();
                    str3 = strArray[2].ToString();
                    return (str2 + "/" + str + "/" + str3);

                case 1:
                    strArray = ngay.Split(new char[] { '/' });
                    str = strArray[0].ToString();
                    str2 = strArray[1].ToString();
                    str3 = strArray[2].ToString();
                    return (str + "/" + str2 + "/" + str3);
            }
            return "";
        }

        public static void ReadConfig()
        {
            if (File.Exists(@"D:\\Data\Config.txt"))
            {
                FileStream stream = new FileStream(@"D:\\Data\Config.txt", FileMode.Open, FileAccess.Read);
                StreamReader reader = new StreamReader(stream);
                string str = "";
                while ((str = reader.ReadLine()) != null)
                {
                    string[] strArray = str.Split(new char[] { ',' });
                    if (strArray[0].ToString() == "BanHang")
                    {
                        ConfigSale = int.Parse(strArray[1].ToString());
                    }
                }
                reader.Close();
                stream.Close();
            }
        }

        public static void WriteConfig()
        {
            if (!Directory.Exists(@"D:\\Data"))
            {
                Directory.CreateDirectory(@"D:\\Data");
            }
            if (!File.Exists(@"D:\\Data\Config.txt"))
            {
                FileStream stream = new FileStream(@"D:\\Data\Config.txt", FileMode.Create, FileAccess.Write);
                StreamWriter writer = new StreamWriter(stream);
                writer.WriteLine("BanHang," + 1);
                writer.Close();
                stream.Close();
            }
        }
    }

 

}
